var express=require('express');
var router=express.Router();


const http = require('http');
const url = require('url');
const sql = require('mysql');

var TEST_DATABASE = 'bigevent';  
var TEST_TABLE = 'bigevent'; 

var con = sql.createConnection({
    host: 'localhost',
    user:'root',
    password:'694310908',
    database:TEST_DATABASE
});

con.connect();

function onRequest(req,res){
    console.log("new Request: getLine");
    var arg1 = url.parse(req.url,true).query;
    // console.log(arg1.name);

    con.query('select distinct YEAR(date)as year from bigevent order by year asc',function(e,sqlres,f){
        if(e){
            throw e;
        }
        if(sqlres){
            var myarry =[];
            for(var i=0;i<sqlres.length;i++){
               myarry.push({'time':sqlres[i].year});
                
            }
           
            res.writeHead(200,{'Access-Control-Allow-Origin':'*'});

            res.end(JSON.stringify({'timeline':myarry}));
        }
    } );
     


}

router.get('/',onRequest);

module.exports=router;
